#include <bits/stdc++.h>
using namespace std;
struct stu{
    string id;
    int test;
    int exam;
};
int main() {
    int n,t;
    cin>>n;
    stu arr[n];
    string id;
    int test;
    int exam;
    for (int i = 0; i < n; ++i) {
        cin>>id>>test>>exam;
        arr[test-1].id = id;
        arr[test-1].test = test;
        arr[test-1].exam = exam;
    }
    cin>>n;
    for (int i = 0; i < n; ++i) {
        cin>>t;
        cout<<arr[t-1].id<<" "<<arr[t-1].exam<<endl;
    }
}
